bitkeeper revision 1.332 (3f0d4a71ScYIvhpYjrv_aLLacdn4Ig)
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Thu, 10 Jul 2003 11:13:53 +0000 (11:13 +0000)
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Thu, 10 Jul 2003 11:13:53 +0000 (11:13 +0000)
Remove on-disk storage of virtual block devices
Implement retrieving VBD info from /proc
remove VBD delete and flush commands as VBDs go away by themselves when their domains are destroyed

14 files changed:
.rootkeys
tools/control/src/org/xenoserver/cmdline/Main.java
tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java [deleted file]
tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
tools/control/src/org/xenoserver/control/CommandVbdCreate.java
tools/control/src/org/xenoserver/control/CommandVbdDelete.java [deleted file]
tools/control/src/org/xenoserver/control/CommandVbdFlush.java [deleted file]
tools/control/src/org/xenoserver/control/CommandVbdList.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandVdDelete.java
tools/control/src/org/xenoserver/control/VirtualBlockDevice.java
tools/control/src/org/xenoserver/control/VirtualDiskManager.java
tools/control/src/org/xenoserver/control/XMLHelper.java

index b38025b6caf003792207f17543a3aa74afbc7e08..e45e73bb1bd2ac5f0b7ddbaa59d3adb6ed4c913a 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -29,8 +29,6 @@
 3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
 3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
 3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
-3f0bf89f_DkClyexDd4EDwinZJG83A tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
-3f0bf89fvzPQqcHBq1xA0XlFiO8tLA tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
 3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
 3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
 3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
@@ -50,8 +48,7 @@
 3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
 3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
 3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
-3f0bf89fcVy1cFU18hPVXkFMMLHLug tools/control/src/org/xenoserver/control/CommandVbdDelete.java
-3f0bf8a0aRDXkIGy3liS1oKXIQpeyA tools/control/src/org/xenoserver/control/CommandVbdFlush.java
+3f0d4a70B132OMLyoUBFJAfNCATCww tools/control/src/org/xenoserver/control/CommandVbdList.java
 3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
 3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
 3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
index caf3451437d9a7d09276dbfd26e815dbd0d97ced..3b8cc554b7873b6e3b229e8bfaec10ca3354887e 100644 (file)
@@ -36,8 +36,6 @@ public class Main {
     };
   private static final CommandParser vbdcommands[] =
     { new ParseVbdCreate(),
-      new ParseVbdDelete(),
-      new ParseVbdFlush(),
       new ParseVbdShow()
     };
   private static final CommandParser commands[] =
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
deleted file mode 100644 (file)
index f0a9786..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdDelete;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdDelete extends CommandParser {
-    public void parse(Defaults d, LinkedList args)
-        throws ParseFailedException, CommandFailedException {
-        int domain_id = getIntParameter(args, 'n', 0);
-        int vbd_num = getIntParameter(args, 'v', -1);
-
-        if (domain_id == 0) {
-            throw new ParseFailedException("Expected -n<domain_id>");
-        }
-        if (vbd_num == -1) {
-            throw new ParseFailedException("Expected -v<vbd_num>");
-        }
-        loadState();
-        String output = new CommandVbdDelete(domain_id, vbd_num).execute();
-        if (output != null) {
-            System.out.println(output);
-        }
-        saveState();
-    }
-
-    public String getName() {
-        return "delete";
-    }
-
-    public String getUsage() {
-        return "-n<domain> -v<vbd>";
-    }
-
-    public String getHelpText() {
-        return "Deletes the specified virtual block device from the specified domain.";
-    }
-
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
deleted file mode 100644 (file)
index 3043900..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdFlush;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdFlush extends CommandParser {
-    public void parse(Defaults d, LinkedList args)
-        throws ParseFailedException, CommandFailedException {
-        loadState();
-        String output = new CommandVbdFlush().execute();
-        if (output != null) {
-            System.out.println(output);
-        }
-        saveState();
-    }
-
-    public String getName() {
-        return "flush";
-    }
-
-    public String getUsage() {
-        return "";
-    }
-
-    public String getHelpText() {
-        return "Delete all virtual block devices";
-    }
-}
index b89105d592fa4109f726f7b7a940b2e06234669f..b35c9e068db29691f1cda246984f5d840dd7e11a 100644 (file)
@@ -1,29 +1,29 @@
 package org.xenoserver.cmdline;
 
-import java.util.Iterator;
 import java.util.LinkedList;
 
 import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdList;
 import org.xenoserver.control.Defaults;
 import org.xenoserver.control.Library;
 import org.xenoserver.control.VirtualBlockDevice;
-import org.xenoserver.control.VirtualDiskManager;
 
 public class ParseVbdShow extends CommandParser {
     public void parse(Defaults d, LinkedList args)
         throws ParseFailedException, CommandFailedException {
         loadState();
-        Iterator i = VirtualDiskManager.IT.getVirtualBlockDevices();
+        CommandVbdList list = new CommandVbdList();
+        list.execute();
+        VirtualBlockDevice[] vbds = list.vbds();
         System.out.println("key         dom vbd mode");
-        while (i.hasNext()) {
-            VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
-            System.out.println( vbd.getVirtualDisk().getKey()
+        for (int i=0; i<vbds.length; i++) {
+            System.out.println( vbds[i].getVirtualDisk().getKey()
                     + "  "
-                    + Library.format(vbd.getDomain(), 3, false)
+                    + Library.format(vbds[i].getDomain(), 3, false)
                     + " "
-                    + Library.format(vbd.getVbdNum(), 3, false)
+                    + Library.format(vbds[i].getVbdNum(), 3, false)
                     + " "
-                    + vbd.getMode().toString());
+                    + vbds[i].getMode().toString());
         }
     }
 
index cfbce4a4232ed152ed1e2a816a6c8485a0a5a347..842f97787137c97662d9e691d06b2be96907c6a7 100644 (file)
@@ -10,13 +10,14 @@ public class ParseVdDelete extends CommandParser {
     public void parse(Defaults d, LinkedList args)
         throws ParseFailedException, CommandFailedException {
         String vd_key = getStringParameter(args, 'k', "");
+        boolean force = getFlagParameter(args,'f');
 
         if (vd_key.equals("")) {
             throw new ParseFailedException("Expected -k<key>");
         }
 
         loadState();
-        String output = new CommandVdDelete(vd_key).execute();
+        String output = new CommandVdDelete(vd_key,force).execute();
         if (output != null) {
             System.out.println(output);
         }
@@ -29,11 +30,11 @@ public class ParseVdDelete extends CommandParser {
     }
 
     public String getUsage() {
-        return "-k<key>";
+        return "-k<key> [-f]";
     }
 
     public String getHelpText() {
-        return "Deletes the virtual disk with the specified key.";
+        return "Deletes the virtual disk with the specified key. -f forces deletion even if the disk is in use.";
     }
 
 }
index 8ac08832640ca0ec8d3e92104acc07d09f6d6dbc..3c1c21aa6c2e16f1126ab76b5a9fa069c4030e6f 100644 (file)
@@ -45,7 +45,7 @@ public class CommandVbdCreate extends Command {
         }
 
         VirtualBlockDevice vbd =
-            VirtualDiskManager.IT.createVirtualBlockDevice(
+            new VirtualBlockDevice(
                 vd,
                 domain_id,
                 vbd_num,
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdDelete.java b/tools/control/src/org/xenoserver/control/CommandVbdDelete.java
deleted file mode 100644 (file)
index ca1cd1e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Delete a virtual block device. Note that this does not update anything inside
- * Xen, and therefore should only be done if you are certain that the domain has
- * either not been started, or has been destroyed, or you are sure it will not
- * try to access the VBD again. Since the mapping is not removed in Xen, any
- * subsequent changes to the underlying virtual disk will affect the domain,
- * probably adversely.
- */
-public class CommandVbdDelete extends Command {
-    /** Domain id to delete from */
-    private int domain_id;
-    /** VBD number to delete */
-    private int vbd_num;
-
-    /**
-     * Constructor for CommandVbdDelete.
-     * @param domain_id Domain ID to delete from
-     * @param vbd_num VBD number to delete
-     */
-    public CommandVbdDelete(int domain_id, int vbd_num) {
-        this.domain_id = domain_id;
-        this.vbd_num = vbd_num;
-    }
-
-    /**
-     * @see org.xenoserver.control.Command#execute()
-     */
-    public String execute() throws CommandFailedException {
-        if (VirtualDiskManager
-            .IT
-            .deleteVirtualBlockDevice(domain_id, vbd_num)) {
-            return "Deleted VBD " + vbd_num + " from domain " + domain_id;
-        } else {
-            throw new CommandFailedException(
-                "No such virtual block device "
-                    + vbd_num
-                    + " in domain "
-                    + domain_id);
-        }
-    }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdFlush.java b/tools/control/src/org/xenoserver/control/CommandVbdFlush.java
deleted file mode 100644 (file)
index fdb5b12..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Flush (delete) all virtual block devices.
- */
-public class CommandVbdFlush extends Command {
-    /**
-     * @see org.xenoserver.control.Command#execute()
-     */
-    public String execute() throws CommandFailedException {
-        VirtualDiskManager.IT.flushVirtualBlockDevices();
-        return "Flushed virtual block devices";
-    }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdList.java b/tools/control/src/org/xenoserver/control/CommandVbdList.java
new file mode 100644 (file)
index 0000000..e525ee4
--- /dev/null
@@ -0,0 +1,66 @@
+package org.xenoserver.control;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class CommandVbdList extends Command {
+    /** Array of virtual block devices returned */
+    private VirtualBlockDevice[] array;
+
+    public String execute() throws CommandFailedException {
+        Vector v = new Vector();
+        BufferedReader in;
+        String line;
+
+        try {
+            in = new BufferedReader(new FileReader("/proc/xeno/dom0/vhd"));
+            line = in.readLine();
+            while (line != null) {
+                int domain = -1;
+                int vbdnum = -1;
+                String key = "";
+                Mode mode = Mode.READ_ONLY;
+
+                StringTokenizer st = new StringTokenizer(line);
+                if (st.hasMoreTokens()) {
+                    domain = Integer.parseInt(st.nextToken());
+                }
+                if (st.hasMoreTokens()) {
+                    vbdnum = Integer.parseInt(st.nextToken());
+                }
+                if (st.hasMoreTokens()) {
+                    key = st.nextToken();
+                }
+                if (st.hasMoreTokens()) {
+                    if (Integer.parseInt(st.nextToken()) == 2) {
+                        mode = Mode.READ_WRITE;
+                    }
+                }
+
+                VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
+                if (vd == null) {
+                    throw new CommandFailedException(
+                        "Key " + key + " has no matching virtual disk");
+                }
+                VirtualBlockDevice vbd =
+                    new VirtualBlockDevice(vd, domain, vbdnum, mode);
+                v.add(vbd);
+
+                line = in.readLine();
+            }
+        } catch (IOException e) {
+            throw new CommandFailedException("Could not read VBD file", e);
+        }
+
+        array = new VirtualBlockDevice[v.size()];
+        v.toArray(array);
+        return null;
+    }
+    
+    public VirtualBlockDevice[] vbds() {
+        return array;
+    }
+}
index 6fadde859c2ad58ff4ba669156b7b2e5c9010c6b..2873cd2bebe1fc5eca6720eaec38b7091c9ffc10 100644 (file)
@@ -6,13 +6,16 @@ package org.xenoserver.control;
 public class CommandVdDelete extends Command {
     /** Key of disk to delete. */
     private String key;
+    /** Force deletion? */
+    private boolean force;
 
     /**
      * Constructor for CommandVdDelete.
      * @param key The key of the disk to delete.
      */
-    public CommandVdDelete(String key) {
+    public CommandVdDelete(String key,boolean force) {
         this.key = key;
+        this.force = force;
     }
 
     /**
@@ -23,6 +26,16 @@ public class CommandVdDelete extends Command {
             throw new CommandFailedException(
                 "Virtual disk " + key + " does not exist");
         }
+        if ( !force ) {
+            CommandVbdList list = new CommandVbdList();
+            list.execute();
+            VirtualBlockDevice[] vbds = list.vbds();
+            for (int i=0;i<vbds.length;i++) {
+                if (vbds[i].getVirtualDisk().getKey().equals(key)) {
+                    throw new CommandFailedException("Virtual disk " + key + " is in use.");
+                }
+            }
+        }
 
         VirtualDiskManager.IT.deleteVirtualDisk(key);
         return "Deleted virtual disk " + key;
index 6e7c64480a60389af67f041c356513a564f588f5..2b1a5ceb211ad2a137b2cdb6b99157291e8db43b 100644 (file)
@@ -5,8 +5,6 @@
 
 package org.xenoserver.control;
 
-import java.io.PrintWriter;
-
 /**
  * A virtual block device; a mapping from a domain-specific number to a virtual
  * disk with associated access mode.
@@ -39,19 +37,6 @@ public class VirtualBlockDevice {
         this.mode = mode;
     }
 
-    /**
-     * Dump the virtual block device as XML.
-     * @param out The writer to dump to.
-     */
-    void dumpAsXML(PrintWriter out) {
-        out.println("  <virtual_block_device>");
-        out.println("    <key>" + vd.getKey() + "</key>");
-        out.println("    <domain>" + domain + "</domain>");
-        out.println("    <vbdnum>" + vbdNum + "</vbdnum>");
-        out.println("    <mode>" + mode + "</mode>");
-        out.println("  </virtual_block_device>");
-    }
-
     /**
      * @return This device's virtual disk.
      */
index 179ee079a4cbea7b0e5847b6bc6044f482535ba8..8ff9041e8c49e030b5d1bede858e6efb6075f942 100644 (file)
@@ -21,8 +21,6 @@ public class VirtualDiskManager {
     private VirtualDisk freeDisk;
     /** The map of keys to virtual disks. */
     private LinkedHashMap virtualDisks = new LinkedHashMap(100);
-    /** The map of (domain,vbdnum) to virtual block devices. */
-    private LinkedHashMap virtualBlockDevices = new LinkedHashMap(100);
 
     /**
      * VDM constructor, private as it's a singleton.
@@ -100,46 +98,6 @@ public class VirtualDiskManager {
         }
     }
 
-    /**
-     * Create a new virtual block device.
-     * @param vd The virtual disk to expose.
-     * @param domain The domain to create the device for.
-     * @param vbdNum The block device number to use.
-     * @param mode The mode to create the device with.
-     * @return The newly created virtual block device.
-     */
-    VirtualBlockDevice createVirtualBlockDevice(
-        VirtualDisk vd,
-        int domain,
-        int vbdNum,
-        Mode mode) {
-        VirtualBlockDevice vbd =
-            new VirtualBlockDevice(vd, domain, vbdNum, mode);
-
-        insertVirtualBlockDevice(vbd);
-
-        return vbd;
-    }
-
-    /**
-     * Delete a virtual block device.
-     * @param domain Domain owning the device.
-     * @param vbdNum The vbd number within the domain.
-     * @return true if the VBD was deleted, false if it does not exist.
-     */
-    boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
-        Object hash = hashVBD(domain, vbdNum);
-        return virtualBlockDevices.remove(hash) != null;
-    }
-
-    /**
-     * Flush all virtual block devices.
-     */
-    void flushVirtualBlockDevices() {
-        /* isn't automatic garbage collection wonderful? */
-        virtualBlockDevices = new LinkedHashMap(100);
-    }
-
     /**
      * Insert a new virtual disk into the map.
      * @param vd The disk to insert.
@@ -148,15 +106,6 @@ public class VirtualDiskManager {
         virtualDisks.put(vd.getKey(), vd);
     }
 
-    /**
-     * Insert a new virtual block device into the map.
-     * @param vbd The device to insert.
-     */
-    void insertVirtualBlockDevice(VirtualBlockDevice vbd) {
-        Object hash = hashVBD(vbd.getDomain(), vbd.getVbdNum());
-        virtualBlockDevices.put(hash, vbd);
-    }
-
     /**
      * Hash a virtual block device.
      * @param domain The VBD's domain.
@@ -190,14 +139,6 @@ public class VirtualDiskManager {
             vd.dumpAsXML(out);
         }
         out.println("</virtual_disks>");
-        out.println("<virtual_block_devices>");
-        i = virtualBlockDevices.values().iterator();
-        while (i.hasNext()) {
-            VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
-            vbd.dumpAsXML(out);
-        }
-
-        out.println("</virtual_block_devices>");
     }
 
     /**
@@ -207,13 +148,6 @@ public class VirtualDiskManager {
         return freeDisk;
     }
 
-    /**
-     * @return An iterator over the virtual block devices.
-     */
-    public Iterator getVirtualBlockDevices() {
-        return virtualBlockDevices.values().iterator();
-    }
-
     /**
      * @return An iterator over the virtual disks.
      */
index 1f93844dd25d5facfa9d45c995c34a184b1ee493..abdfe924ca4b7cafd4b5597927430cc7029c5acd 100644 (file)
@@ -100,13 +100,6 @@ class XMLHelper {
                         + "]");
             }
         }
-
-        /* parse virtual block devices */
-        parseVirtualBlockDevices(
-            vdm,
-            document.getElementsByTagName("virtual_block_device"));
-
-        return;
     }
 
     /**
@@ -190,35 +183,4 @@ class XMLHelper {
             pm.addXenoPartition(partition);
         }
     }
-
-    /**
-     * Parse a list of virtual block device nodes.
-     * @param vdm The VirtualDiskManager to configure. 
-     * @param nl The node list.
-     */
-    private static void parseVirtualBlockDevices(
-        VirtualDiskManager vdm,
-        NodeList nl) {
-        for (int loop = 0; loop < nl.getLength(); loop++) {
-            Node node = nl.item(loop);
-            Mode mode;
-
-            if (XMLHelper
-                .getText(XMLHelper.getSubNode("mode", node))
-                .equals("rw")) {
-                mode = Mode.READ_WRITE;
-            } else {
-                mode = Mode.READ_ONLY;
-            }
-
-            vdm.createVirtualBlockDevice(
-                vdm.getVirtualDisk(
-                    XMLHelper.getText(XMLHelper.getSubNode("key", node))),
-                Integer.parseInt(
-                    XMLHelper.getText(XMLHelper.getSubNode("domain", node))),
-                Integer.parseInt(
-                    XMLHelper.getText(XMLHelper.getSubNode("vbdnum", node))),
-                mode);
-        }
-    }
 }